"""
<name>Parents Selection Method</name>
<description>Parents selection method</description>
<contact>Leidy Garzon</contact>
<icon>icons/Selector.svg</icon>
<priority>1060</priority>

"""
from Goldenberry.widgets import *
from Goldenberry.widgets import selection_functions

class GbSelectorWidget(OWWidget):
    """Parents selection method"""
    
    #attributes
    selection_index = 0

    def __init__(self, parent=None, signalManager=None):
        OWWidget.__init__(self, parent, signalManager, 'Parents selection method')
        self.get_selections()
        self.setup_interfaces()
        self.setup_ui() 

    def setup_interfaces(self):
        self.outputs = [("Selector", Selector)]

    def get_selections(self):
        self.selections = dict(inspect.getmembers(selection_functions, lambda member: inspect.isclass(member)))
        del self.selections['SelectionStrategy'] 

    def setup_ui(self):
        # Loads the UI from an .ui file.
        load_widget_ui(self)
        
        #set new binding controls
        selection_combobox = OWGUI.comboBox(self, self, "selection_index", items = self.selections, tooltip = "Select the parents selection method")
        self.paramBox.setLayout(QFormLayout(self.paramBox))
        self.paramBox.layout().addRow(OWGUI.QLabel('Select the parents selection method')) 
        self.paramBox.layout().addRow(selection_combobox)

        # Subscribe to signals
        QObject.connect(self.applyButton,QtCore.SIGNAL("clicked()"), self.apply_selection)
    def selection_selected(self):
        pass

    def apply_selection(self):
        selector = Selector()
        selector.set_selection(self.selections.values()[self.selection_index].__name__)
        self.accept()
        self.send("Selector", selector)

if __name__=="__main__":
    test_widget()

def test_widget():
    appl = QApplication(sys.argv)
    ow = GbSelectorWidget()
    ow.show()
    appl.exec_()